<?php
    class admin_hotproduct_controller extends controllerBase
    {
        public function process()
        {
            $oDatabase = new database();
            // Get Product to data Autocomplete
            //$aListProduct = $oDatabase->getListObject("
            //                            select masp_id,tensp,tendm,dongia from sanpham,danhmuc where sanpham.madm_id = danhmuc.madm_id");
            //            $this->aParams['list_product']=$aListProduct;
            $query='PREFIX foaf: <http://xmlns.com/foaf/0.1/>
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>
            PREFIX bus: <'.URL::getLink('id/bussiness#').'>

            SELECT * 
            WHERE
            {
            ?uri rdf:type bus:product.
            ?uri bus:name ?name. 
            ?uri bus:description ?description.
            ?uri bus:price ?price.
            ?uri bus:hasCategory ?category.
            ?category bus:name ?categoryname.
            }';
            $hotProducts = $oDatabase->loadQuery($query);   
            $this->aParams['list_product']=$hotProducts['result']['rows'];
//            print(count($hotProducts['result']['rows']));


            // Get Product Hot to table
            $aListProducts = $oDatabase->getListObject("select * from sanphamhot ");// Get all Id sanphamhot table
            $subquery ='';// cau so sanh
            $cout=0;
            foreach($aListProducts as $product)
            {
                $cout+=1;
                $subquery = $subquery.'?uri = "'.URL::getLink('product/id/'.$product->masp_id).'"';
                if($cout<count($aListProducts)) 
                {
                    $subquery =$subquery. '||';
                }
            }
            $this->aParams['productHots'] = array();
            if($subquery != '')
            {
                $query='PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                PREFIX dc: <http://purl.org/dc/elements/1.1/>
                PREFIX bus: <'.URL::getLink('id/bussiness#').'>

                SELECT * 
                WHERE
                {
                ?uri rdf:type bus:product.
                ?uri bus:name ?name. 
                ?uri bus:description ?description.
                ?uri bus:price ?price.
                ?uri bus:category ?category.
                ?category bus:name ?categoryname
                FILTER('.$subquery.')
                }';
                $hotProducts = $oDatabase->loadQuery($query);   
                $this->aParams['productHots']=$hotProducts['result']['rows'];
            }

        }
    }
?>
